using System;
using System.Text;
using System.Web.UI.WebControls;
using SpiderMaster.AspNet.TradingSystem.BusinessLogicLayer;

namespace SpiderMaster.AspNet.TradingSystem.UI
{
    public partial class Login_aspx : TradingCenterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated && LinkManager.ReceiveUrlQuery(QueryOperator.NoticeActive, false))
                new Redirect(LinkManager.AppendUrl(VirtualPage.MyDefault, QueryOperator.NoticeActive, true, QueryOperator.NoticeType, NoticeType.IsNotInRole));
            else if (!Page.IsPostBack)
                AccessNoticePanel.Visible = LinkManager.ReceiveUrlQuery(QueryOperator.NoticeActive, false) ? true : (Request.QueryString["ReturnUrl"] != null);
        }
        protected void ForgotPasswordButton_Click(object sender, EventArgs e)
        {
            this.PasswordRecovery.Visible = true;
        }

        protected void PasswordRecovery_Init(object sender, EventArgs e)
        {
            PasswordRecovery.MailDefinition.From = SiteSettings.Current.MailSenderAddressFormatted;
        }
        protected void PasswordRecovery_SendMailError(object sender, SendMailErrorEventArgs e)
        {
            StringBuilder mailLink = new StringBuilder("<a href=\"mailto:");

            try { mailLink.Append(SiteSettings.Current.SiteEmailAddress); }
            catch { mailLink.Append("#"); }

            mailLink.Append("\">system Administrator</a>");
            PasswordRecovery.SuccessText = "A problem occurred sending the email. " +
                "Please contact the " + mailLink.ToString() + ".";
            e.Handled = true;
        }
    }
}
